feat: add randomSeed argument to COIN_CMD for reproducible CBC solves (#613) - #936
Open
haiiibin wants to merge 1 commit into
Open
feat: add randomSeed argument to COIN_CMD for reproducible CBC solves (#613)#936haiiibin wants to merge 1 commit into
haiiibin wants to merge 1 commit into
Conversation
COIN_CMD exposes threads, maxNodes, timeMode, etc. as constructor arguments that map to CBC command-line options, but the random seed (CBC's -randomSeed) could previously only be set through the generic `options` list. Controlling the seed is the standard way to make MIP solves reproducible (and can also change solve time), so expose it directly. Add a randomSeed keyword argument that flows into optionsDict and is emitted as `-randomSeed <n>` via getOptions, mirroring the existing threads/maxNodes handling. (PULP_CBC_CMD was removed, so COIN_CMD, the default CBC entry point, is where this belongs.) Add a test mirroring test_strong that solves with a seed and asserts -randomSeed appears on the command line.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
COIN_CMDalready exposesthreads,maxNodes,timeMode,gapRel, etc. as constructor arguments that translate to CBC command-line options, but the random seed (CBC's-randomSeed) could previously only be set through the genericoptionslist, e.g.COIN_CMD(options=["randomSeed 20"]). Setting the seed is the standard way to make MIP solves reproducible (and can also change solve time), so it is worth exposing directly. This was requested in #613 and seconded there by a contributor.Change
randomSeedkeyword argument toCOIN_CMD.__init__. It flows intooptionsDictlike the other options and is emitted as-randomSeed <n>fromgetOptions, mirroring the existingthreads/maxNodeshandling.PULP_CBC_CMD, but that class no longer exists;COIN_CMDis the current CBC entry point (and the default solver), so the argument lives there.Verification
-randomSeed <n>and solves to optimality (against PuLP's CBC binary).getOptions()emitsrandomSeed 20whenrandomSeed=20is set, so-randomSeed 20appears on the solver command line.test_random_seed(inCOIN_CMD_CBCOptionsTest) mirroring the existingtest_strong: it solves a small MIP with a seed, reads the command line back from the log file, and asserts-randomSeed 20is present; it also asserts the constructor argument populatesoptionsDict.Closes #613.